//
//  HTPackageItem.swift
//  MagaCore
//
//  Created by MrMessy on 2023/5/8.
//

import SwiftUI

struct HTPackageItem: View {

  var var_subscribe: HTSubscribe = HTSubscribe()
  var var_isSel: Bool = true

  var body: some View {
    ZStack(alignment: .topLeading){
      VStack(alignment: .leading, spacing: 0){
        HStack{
        }
        .frame(width: UIDevice.ht_fixToWidth(width: 70), height: UIDevice.ht_fixToWidth(width: 24))

        Text(var_subscribe.var_title ?? "")
          .font(.system(size: UIDevice.ht_fixToWidth(width: 12)))
          .foregroundColor(var_isSel ? Color.white : Color(hex: "#393939"))
          .frame(maxWidth: .infinity)
          .padding(.top, 6)
        Text("$\(var_subscribe.var_price ?? 0)")
          .font(.system(size: UIDevice.ht_fixToWidth(width: 24)))
          .fontWeight(.medium)
          .foregroundColor(var_isSel ? Color.white : Color(hex: "#393939"))
          .frame(maxWidth: .infinity)
          .padding(.top, 8)
        Text("$\(var_subscribe.var_origin_price ?? 0)")
          .strikethrough()
          .font(.system(size: UIDevice.ht_fixToWidth(width: 12)))
          .foregroundColor(var_isSel ? Color.white : Color(hex: "#999999"))
          .frame(maxWidth: .infinity)
          .padding(.top, 15)
      }
      .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)

      if (var_subscribe.var_introductoryPrice != nil) {
        HStack{
          Text("Trial")
            .font(.system(size: UIDevice.ht_fixToWidth(width: 14)))
            .ht_normal()
        }
        .frame(width: UIDevice.ht_fixToWidth(width: 70), height: UIDevice.ht_fixToWidth(width: 24))
        .background(LinearGradient(colors: [Color(hex: "#EDC391"), Color(hex: "#FDDDB7")], startPoint: .leading, endPoint: .trailing))
        .clipShape(HTRroundedCorners(var_br: UIDevice.ht_fixToWidth(width: 6)))
      } else {
        if (var_subscribe.var_isBestPrice == true) {
          HStack{
            Text("Best Price")
              .font(.system(size: UIDevice.ht_fixToWidth(width: 14)))
              .ht_normal()
          }
          .frame(width: UIDevice.ht_fixToWidth(width: 70), height: UIDevice.ht_fixToWidth(width: 24))
          .background(LinearGradient(colors: [Color(hex: "#EDC391"), Color(hex: "#FDDDB7")], startPoint: .leading, endPoint: .trailing))
          .clipShape(HTRroundedCorners(var_br: UIDevice.ht_fixToWidth(width: 6)))
        }
      }
    }
    .frame(width: UIDevice.ht_fixToWidth(width: 110), height: UIDevice.ht_fixToWidth(width: 134), alignment: .topLeading)
    .background(var_isSel ? LinearGradient(colors: [Color(hex: "#FF6D1C"), Color(hex: "#FF1C1C")], startPoint: .trailing, endPoint: .leading) : LinearGradient(colors: [Color.white, Color.white], startPoint: .trailing, endPoint: .leading))
    .cornerRadius(UIDevice.ht_fixToWidth(width: 6))
  }
}
